<?php require_once('../Connections/locale.php'); ?>
<?php
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form1")) {
  $updateSQL = sprintf("UPDATE siteoptions SET smtp_server=%s, smtp_port=%s, sender_address=%s WHERE sitename=%s",
                       GetSQLValueString($_POST['smtp_server'], "text"),
                       GetSQLValueString($_POST['smtp_port'], "text"),
                       GetSQLValueString($_POST['sender_address'], "text"),
                       GetSQLValueString($_POST['sitename'], "text"));

  mysql_select_db($database_locale, $locale);
  $Result1 = mysql_query($updateSQL, $locale) or die(mysql_error());

  $updateGoTo = "../opzioni.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
    $updateGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $updateGoTo));
}

mysql_select_db($database_locale, $locale);
$query_opzioni_mail = "SELECT * FROM siteoptions WHERE sitename = 'Gestione_Abbonamenti'";
$opzioni_mail = mysql_query($query_opzioni_mail, $locale) or die(mysql_error());
$row_opzioni_mail = mysql_fetch_assoc($opzioni_mail);
$totalRows_opzioni_mail = mysql_num_rows($opzioni_mail);

mysql_free_result($opzioni_mail);
?>
<link href="../style.css" rel="stylesheet" type="text/css">

<form method="post" name="form1" action="<?php echo $editFormAction; ?>">
  <table align="left">
    <tr valign="baseline">
      <td nowrap align="right">Server SMTP :</td>
      <td><input type="text" name="smtp_server" value="<?php echo $row_opzioni_mail['smtp_server']; ?>" size="32"></td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right">Porta:</td>
      <td><input type="text" name="smtp_port" value="<?php echo $row_opzioni_mail['smtp_port']; ?>" size="32"></td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right">Mittente:</td>
      <td><input type="text" name="sender_address" value="<?php echo $row_opzioni_mail['sender_address']; ?>" size="32"></td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right">&nbsp;</td>
      <td><input type="submit" value="Salva Impostazioni"></td>
    </tr>
  </table>
  <input type="hidden" name="MM_update" value="form1">
  <input type="hidden" name="sitename" value="<?php echo $row_opzioni_mail['sitename']; ?>">
</form>
<p>&nbsp;</p>
